* Change the directory to the top one for this project
set more off
capture cd "C:\Users\Benjamin Allen\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "C:\Users\balle\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "~\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "C:\Users\balle\Dropbox (Personal)\Papers\Support for Algorithmic Governance"

use "data/Combined EPIS and Canadian data recoded and labeled with scales.dta", clear

********************************************************************************
* multilevel models
********************************************************************************

codebook alg_govt_acceptable_scale_bi
*hist alg_govt_acceptable_scale_bi

codebook 	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled

	/* MOVED TO THE FILE THAT CREATES THE SCALES, after the code that makes the histograms

*------------------------------------------------------------------------------*
* Comparing distributions of the number of reasons found acceptable in different countries
*------------------------------------------------------------------------------*

preserve

collapse (count) N = age_in_years, by(alg_govt_acceptable_scale_bi country_recoded)

* Calculating the N for each country
gen country_N = 0
sort country_recoded
by country_recoded: ereplace country_N = total(N)

* Calculate the proportion of the population within each country that supports each number of reasons
gen num_reasons_percent = N / country_N

* Need to re-sort it so that the lines connect in a reasonable way
sort alg_govt_acceptable_scale_bi

* De-scale the DV back to 0-8 temporarily
replace alg_govt_acceptable_scale_bi = alg_govt_acceptable_scale_bi*8
lab var alg_govt_acceptable_scale_bi "Binary acceptance of algorithmic governance (scaled 0-8)"

* graphing ideological variance by rural/urban
* The Kdensity area value OUGHT to be the # of rural or urban ridings, respectively, multiplied by the bin width. In this case I mistakenly used 335 for both, when the SUM of both should be 335
graph twoway ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Austria":country_recoded,		color(red%40)		msymbol(triangle)	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Belgium (FR)":country_recoded, 	color(sand%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Belgium (NL)":country_recoded, 	color(sandb%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Canada":country_recoded, 		color(red*1.3%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Denmark":country_recoded, 		color(cranberry%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Finland":country_recoded, 		color(edkblue%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "France":country_recoded, 		color(ebblue%40)	msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Germany":country_recoded, 		color(maroon%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Greece":country_recoded, 		color(eltblue%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Ireland":country_recoded, 		color(dkorange%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Italy":country_recoded, 			color(midgreen%40)	msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Netherlands":country_recoded, 	color(erose%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Norway":country_recoded, 		color(pink%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Portugal":country_recoded, 		color(midgreen%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Spain":country_recoded, 			color(gold%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Sweden":country_recoded, 		color(teal%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "UK":country_recoded, 			color(navy%40)		msymbol(triangle) 	msize(vsmall) ) ///
	, ///
	title("Comparing distribution of acceptance across countries", size(medsmall)) 	///
	ytitle("Proportion") ///
	ylabels(0(0.1)0.4, angle(0) labsize(small)) ///
	xtitle("Number of reasons found acceptable", size(small)) ///
	xlabels(0(1)8, labsize(vsmall)) ///
	legend(order( ///
		1 "Austria" ///
		2 "Belgium (FR)" ///
		3 "Belgium (NL)" ///
		4 "Canada" ///
		5 "Denmark" ///
		6 "Finland" ///
		7 "France" ///
		8 "Germany" ///
		9 "Greece" ///
		10 "Ireland" ///
		11 "Italy" ///
		12 "Netherlands" ///
		13 "Norway" ///
		14 "Portugal" ///
		15 "Spain" ///
		16 "Sweden" ///
		17 "UK" ///
		) col(1) pos(3) size(vsmall)) ///
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/comparing num_reasons distribution across countries.png", width(3300) height(2000) replace

restore
	
exit

*------------------------------------------------------------------------------*
* Comparing distributions of the number of reasons found acceptable in different countries
*------------------------------------------------------------------------------*

preserve

collapse (count) N = age_in_years, by(alg_govt_acceptable_scale_bi country_recoded)

* Calculating the N for each country
gen country_N = 0
sort country_recoded
by country_recoded: ereplace country_N = total(N)

* Calculate the proportion of the population within each country that supports each number of reasons
gen num_reasons_percent = N / country_N

* Need to re-sort it so that the lines connect in a reasonable way
sort alg_govt_acceptable_scale_bi

* De-scale the DV back to 0-8 temporarily
replace alg_govt_acceptable_scale_bi = alg_govt_acceptable_scale_bi*8
lab var alg_govt_acceptable_scale_bi "Binary acceptance of algorithmic governance (scaled 0-8)"

* graphing ideological variance by rural/urban
* The Kdensity area value OUGHT to be the # of rural or urban ridings, respectively, multiplied by the bin width. In this case I mistakenly used 335 for both, when the SUM of both should be 335
graph twoway ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Austria":country_recoded,		color(red%40)		msymbol(triangle)	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Belgium (FR)":country_recoded, 	color(sand%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Belgium (NL)":country_recoded, 	color(sandb%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Canada":country_recoded, 		color(red*1.3%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Denmark":country_recoded, 		color(cranberry%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Finland":country_recoded, 		color(edkblue%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "France":country_recoded, 		color(ebblue%40)	msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Germany":country_recoded, 		color(maroon%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Greece":country_recoded, 		color(eltblue%40)	msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Ireland":country_recoded, 		color(dkorange%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Italy":country_recoded, 			color(midgreen%40)	msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Netherlands":country_recoded, 	color(erose%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Norway":country_recoded, 		color(pink%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Portugal":country_recoded, 		color(midgreen%40)	msymbol(triangle) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Spain":country_recoded, 			color(gold%40)		msymbol(square) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "Sweden":country_recoded, 		color(teal%40)		msymbol(diamond) 	msize(vsmall) ) ///
	(connected num_reasons_percent alg_govt_acceptable_scale_bi if country_recoded == "UK":country_recoded, 			color(navy%40)		msymbol(triangle) 	msize(vsmall) ) ///
	, ///
	title("Comparing distribution of acceptance across countries", size(medsmall)) 	///
	ytitle("Proportion") ///
	ylabels(0(0.1)0.4, angle(0) labsize(small)) ///
	xtitle("Number of reasons found acceptable", size(small)) ///
	xlabels(0(1)8, labsize(vsmall)) ///
	legend(order( ///
		1 "Austria" ///
		2 "Belgium (FR)" ///
		3 "Belgium (NL)" ///
		4 "Canada" ///
		5 "Denmark" ///
		6 "Finland" ///
		7 "France" ///
		8 "Germany" ///
		9 "Greece" ///
		10 "Ireland" ///
		11 "Italy" ///
		12 "Netherlands" ///
		13 "Norway" ///
		14 "Portugal" ///
		15 "Spain" ///
		16 "Sweden" ///
		17 "UK" ///
		) col(1) pos(3) size(vsmall)) ///
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/comparing num_reasons distribution across countries.png", width(3300) height(2000) replace

restore

*/

*------------------------------------------------------------------------------*	
* Checking that our errors are normally distributed
*------------------------------------------------------------------------------*

* The Shapiro-Wilks test is only valid for N <= 2000
*swilk alg_govt_acceptable_scale_bi


sktest alg_govt_acceptable_scale_bi


*------------------------------------------------------------------------------*
* oneway ANOVA
*------------------------------------------------------------------------------*

* Does NOT report ICC
oneway alg_govt_acceptable_scale_bi country_recoded
	
*------------------------------------------------------------------------------*
* loneway ANOVA
*------------------------------------------------------------------------------*	

* Same results as oneway, but DOES report ICC
loneway alg_govt_acceptable_scale_bi country_recoded

*------------------------------------------------------------------------------*
* Random Effects ANOVA
*------------------------------------------------------------------------------*	
	
mixed alg_govt_acceptable_scale_bi, || country_recoded:
	
* Expected proportion of reasons supported is 54.9% (the fixed effects intercept), with a 95% confidence interval of 52.2% to 57.6%
	
* Intra-class correlation
estat icc

* Okay, so when I do a really basic Random Effects ANOVA, we find that coutnry accounts for about 2% of the variance (1% to 4%)
* So, frankly, the country level doesn't matter a whole lot


*------------------------------------------------------------------------------*
* Kruskal-Wallis test
*------------------------------------------------------------------------------*	

* Arguably needed because my variable is non-normally distributed?

kwallis alg_govt_acceptable_scale_bi, by(country_recoded)

* So, they are different?


*------------------------------------------------------------------------------*
* Replicating with a basic ANOVA
*------------------------------------------------------------------------------*	

* Testing assumption #6, homogeneity of variances, with Levene's test
robvar alg_govt_acceptable_scale_bi, by(country_recoded)

* There IS a statistically significant difference in the variance of acceptability between countries
* What does this mean for my ANOVA?
* Some different advice:
*		While that DOES imply that I should be cautious with interpreting the ANOVA: https://www.statology.org/levenes-test-stata/#:~:text=Levene's%20Test%20is%20used%20to,that%20groups%20have%20equal%20variances.
*		There is also advice that one-way ANOVA is robust to heterogeneity of variance WHEN the sample sizes are equal, which is true in this case: https://www.researchgate.net/post/What_to_do_if_Levenes_test_is_significant_in_a_mixed_ANOVA_in_SPSS

oneway alg_govt_acceptable_scale_bi country_recoded, tab

* There is a statistically significant difference between groups (although seemingly small compared to the differences within groups)

* Post hoc testing
pwmean alg_govt_acceptable_scale_bi, over(country_recoded) mcompare(tukey) effects

* This is ridiculous to interpret

*------------------------------------------------------------------------------*
* Replicating with simple ICC
*------------------------------------------------------------------------------*

*icc alg_govt_acceptable_scale_bi country_recoded
* THIS FAILS


*------------------------------------------------------------------------------*
* Basic OLS multilevel model
*------------------------------------------------------------------------------*

*------------------------------------------------------*
* Without demographic controls
*------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?


* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	/// age_in_years_rescaled ///
	/// female ///
	/// low_income ///
	/// education_cat_rescaled ///
	/// Political IVs
	/// lr_scale_rescaled ///
	/// populism_scale ///
	if age_in_years_rescaled != . & female != . & low_income != . & education_cat_rescaled != . & lr_scale_rescaled != . & populism_scale != . ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estat icc	

estimates store mixed_alg_gov_ac_bi_comb_0
	
*------------------------------------------------------*
* Full DV scale <-------------------------------------------------------------------------------------------------------------------------------------------------THIS IS THE MAIN MODEL PRESENTED IN THE PAPER
*------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?


* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estat icc	

* When we add more fixed effects, the ICC for countries is still 2.3% (1.1% to 4.7%)

estimates store mixed_alg_gov_ac_bi_comb_a

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estat icc		
	
estimates store mixed_acc_eff_bi_comb_a

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estat icc	
	
estimates store mixed_acc_fair_bi_comb_a


*------------------------------------------------------------------------------*
* OLS multilevel model with country controls
*------------------------------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?

*------------------------------------------------------*
* Full DV scale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//
	
estat icc

estimates store mixed_alg_gov_ac_bi_comb_b

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estat icc
	
estimates store mixed_acc_eff_bi_comb_b

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estat icc
	
estimates store mixed_acc_fair_bi_comb_b


*------------------------------------------------------------------------------*
* OLS multilevel model with country controls, including leader approval
*------------------------------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?

*------------------------------------------------------*
* Full DV scale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	///
	, /// General options
	emiterate(20) ///
	iterate(20)

estat icc	
	
estimates store mixed_alg_gov_ac_bi_comb_c

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
		///
	, /// General options
	emiterate(20) ///
	iterate(20)

estimates store mixed_acc_eff_bi_comb_c

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	low_income ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	///
	, /// General options
	emiterate(20) ///
	iterate(20)

estimates store mixed_acc_fair_bi_comb_c


********************************************************************************
* Exporting tables of these regressions
********************************************************************************

*---------------------------------------------------------------*
* Tables for use in presentations
*---------------------------------------------------------------*

esttab mixed_alg_gov_ac_bi_comb_0 mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/beamer\mixed_alg_gov_ac_bi_comb_0.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Only country" "Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)

esttab mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/beamer\mixed_alg_gov_ac_bi_comb_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)

esttab mixed_alg_gov_ac_bi_comb_b mixed_acc_eff_bi_comb_b mixed_acc_fair_bi_comb_b using "analysis\tables\combined/beamer\mixed_alg_gov_ac_bi_comb_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with country controls, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)	
	
esttab mixed_alg_gov_ac_bi_comb_c mixed_acc_eff_bi_comb_c mixed_acc_fair_bi_comb_c using "analysis\tables\combined/beamer\mixed_alg_gov_ac_bi_comb_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with leader approval, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)
	
*---------------------------------------------------------------*
* Tables for use in articles
*---------------------------------------------------------------*

esttab mixed_alg_gov_ac_bi_comb_0 mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/article\mixed_alg_gov_ac_bi_comb_0.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Only country" "Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)


esttab mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/article\mixed_alg_gov_ac_bi_comb_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

esttab mixed_alg_gov_ac_bi_comb_b mixed_acc_eff_bi_comb_b mixed_acc_fair_bi_comb_b using "analysis\tables\combined/article\mixed_alg_gov_ac_bi_comb_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with country controls, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)	
	
esttab mixed_alg_gov_ac_bi_comb_c mixed_acc_eff_bi_comb_c mixed_acc_fair_bi_comb_c using "analysis\tables\combined/article\mixed_alg_gov_ac_bi_comb_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with leader approval, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)
	
*---------------------------------------------------------------*
* Standalone tables
*---------------------------------------------------------------*



esttab mixed_alg_gov_ac_bi_comb_0 mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/standalone\mixed_alg_gov_ac_bi_comb_0.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Only country" "Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

esttab mixed_alg_gov_ac_bi_comb_a mixed_acc_eff_bi_comb_a mixed_acc_fair_bi_comb_a using "analysis\tables\combined/standalone\mixed_alg_gov_ac_bi_comb_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic multilevel models, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

esttab mixed_alg_gov_ac_bi_comb_b mixed_acc_eff_bi_comb_b mixed_acc_fair_bi_comb_b using "analysis\tables\combined/standalone\mixed_alg_gov_ac_bi_comb_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with country controls, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)	
	
esttab mixed_alg_gov_ac_bi_comb_c mixed_acc_eff_bi_comb_c mixed_acc_fair_bi_comb_c using "analysis\tables\combined/standalone\mixed_alg_gov_ac_bi_comb_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: multilevel models with leader approval, Combined EPIS and Canadian data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

	
********************************************************************************
* Plotting these results
********************************************************************************	

*------------------------------------------------------------------------------*
* Multilevel logistic regression
*------------------------------------------------------------------------------*

*---------------------------------------------------------------*
* Basic models
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_comb_a , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic multilevel models", size(medsmall)) ///
	subtitle("Full DV scale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_a_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_comb_a , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic multilevel models", size(medsmall)) ///
	subtitle("Efficiency subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		mixed_acc_eff_bi_comb_a:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_a_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_comb_a , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic multilevel models", size(medsmall)) ///
	subtitle("Fairness subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_a_fair.png", width(3300) height(2000) replace

*---------------------------------------------*
* All three combined
*---------------------------------------------*

* I considered figuring out how to put the variance values into coefplot as a note, but decided it isn't worth it

* Normal colour version
coefplot ///
	(mixed_alg_gov_ac_bi_comb_a , label("Full reasons scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	(mixed_acc_eff_bi_comb_a , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	(mixed_acc_fair_bi_comb_a , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.2(.1).2, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic multilevel models", size(medsmall)) ///
	subtitle("Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	///keep(*:) /// Keep all of the equations
	drop(_cons) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	///transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	///eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		/*alg_govt_acceptable_scale_bi:*/_cons = "Constant" ///
		///lns1_1_1:_cons = "Country variance" ///
		///lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	legend(row(1) size(small)) ///
	/*note(///
		"Full reasons scale country variance = X, Residual variance = Y" ///
		"Efficiency subscale country variance = X, Residual variance = Y" ///
		"Fairness subscale country variance = X, Residual variance = Y" ///
	) */  /// 
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_a_comparison_noconstant.png", width(3300) height(2000) replace

* Greyscale version for publication
coefplot ///
	(mixed_alg_gov_ac_bi_comb_a , label("Full reasons scale") mcolor(gs4) msymbol(circle) msize(vsmall) ciopts(lcolor(gs4) lwidth(thin))) ///
	(mixed_acc_eff_bi_comb_a , label("Efficiency subscale") mcolor(gs12) msymbol(circle) msize(vsmall) ciopts(lcolor(gs12) lwidth(thin))) ///
	(mixed_acc_fair_bi_comb_a , label("Fairness subscale") mcolor(gs8) msymbol(circle) msize(vsmall) ciopts(lcolor(gs8) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.2(.1).2, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic multilevel models", size(medsmall)) ///
	subtitle("Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	///keep(*:) /// Keep all of the equations
	drop(_cons) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	///transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	///eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		/*alg_govt_acceptable_scale_bi:*/_cons = "Constant" ///
		///lns1_1_1:_cons = "Country variance" ///
		///lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	legend(row(1) size(small)) ///
	/*note(///
		"Full reasons scale country variance = X, Residual variance = Y" ///
		"Efficiency subscale country variance = X, Residual variance = Y" ///
		"Fairness subscale country variance = X, Residual variance = Y" ///
	) */  /// 
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_a_comparison_noconstant greyscale.png", width(3300) height(2000) replace

*---------------------------------------------------------------*
* Multilevel models with country level controls
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_comb_b , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with country level controls", size(medsmall)) ///
	subtitle("Full DV scale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_b_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_comb_b , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with country level controls", size(medsmall)) ///
	subtitle("Efficiency subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_eff_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_b_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_comb_b , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with country level controls", size(medsmall)) ///
	subtitle("Fairness subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_b_fair.png", width(3300) height(2000) replace

*---------------------------------------------------------------*
* Model with country level controls, including leader approval
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_comb_c , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with leader approval", size(medsmall)) ///
	subtitle("Full DV scale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_c_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_comb_c , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with leader approval", size(medsmall)) ///
	subtitle("Efficiency subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_eff_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_c_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_comb_c , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""multilevel models with leader approval", size(medsmall)) ///
	subtitle("Fairness subscale""Combined EPIS and Canadian data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\combined/coefplots\coefplot-mixed-accept-combined_c_fair.png", width(3300) height(2000) replace
